package com.ruoyi.project.dict.erya.service.impl;

import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.dict.erya.domain.Erya;
import com.ruoyi.project.dict.erya.mapper.EryaMapper;
import com.ruoyi.project.dict.erya.service.IEryaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 尔雅注疏Service业务层处理
 *
 * @author shixiangwen
 * @date 2021-08-16
 */
@Service
@DataSource(DataSourceType.DICT)
public class EryaServiceImpl implements IEryaService {
    @Autowired
    private EryaMapper eryaMapper;

    /**
     * 查询尔雅注疏
     *
     * @param id 尔雅注疏ID
     * @return 尔雅注疏
     */
    @Override
    public Erya selectEryaById(Long id) {
        return eryaMapper.selectEryaById(id);
    }

    /**
     * 查询尔雅注疏列表
     *
     * @param erya 尔雅注疏
     * @return 尔雅注疏
     */
    @Override
    public List<Erya> selectEryaList(Erya erya) {
        List<Erya> eryas = eryaMapper.selectEryaList(erya);
        eryas.forEach(item -> {
            item.setContent(item.getContent().replaceAll("<img[^>]*>", ""));
        });
        return eryas;
    }

    /**
     * 新增尔雅注疏EryaServiceImpl
     *
     * @param erya 尔雅注疏
     * @return 结果
     */
    @Override
    public int insertErya(Erya erya) {
        return eryaMapper.insertErya(erya);
    }

    /**
     * 修改尔雅注疏
     *
     * @param erya 尔雅注疏
     * @return 结果
     */
    @Override
    public int updateErya(Erya erya) {
        return eryaMapper.updateErya(erya);
    }

    /**
     * 删除尔雅注疏对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteEryaByIds(String ids) {
        return eryaMapper.deleteEryaByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除尔雅注疏信息
     *
     * @param id 尔雅注疏ID
     * @return 结果
     */
    @Override
    public int deleteEryaById(Long id) {
        return eryaMapper.deleteEryaById(id);
    }
}
